//
//  AddPopView.swift
//  FastV
//
//  Created by DC on 2024/6/25.
//

import UIKit

class AddPopView: UIView {

    @IBOutlet weak var bgView: UIView!
    //回调
    var completion: ((Int)->())?
    // MARK: -- 初始化方法
    static func view() -> AddPopView {
        let view = Bundle.main.loadNibNamed("AddPopView", owner: nil, options: nil)?.last as! AddPopView
        view.setUI()
        return view
    }
    
    // MARK: -- AwakeFromNib
    override class func awakeFromNib() {
        super.awakeFromNib()
    }
    
    // MARK: -- 设置UI
    private func setUI(){
//        backgroundColor = UIColor.black.withAlphaComponent(0.5)
        layer.opacity = 0.0
        bgView.setRadius(35, corners: [.topLeft,.bottomLeft])
    }

    @IBAction func buttonClick(_ sender: UIButton) {
        let flag = sender.tag - 200
        completion?(flag)
        hidden()
    }
    @IBAction func closeClick(_ sender: UIButton) {
        hidden()
    }
}

// MARK: -- 扩展
extension AddPopView {
    
    ///显示
   func show(){
        let win = UIApplication.shared.keyWindow!
        frame = win.bounds
        win.addSubview(self)
        UIView.animate(withDuration: 0.35) {
            self.layer.opacity = 1.0
        }
    }
    ///隐藏
    func hidden(){
       UIView.animate(withDuration: 0.35) {
           self.layer.opacity = 0.0
       } completion: { _ in
           self.removeFromSuperview()
       }
    }
}

